<?php
class pro_tagihan_telephone_model extends MY_Model {
	var $model = 'pro_tagihan_telephone';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT	no_tagihan_tlp,id_tagihan_tlp,
							TO_CHAR(tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
							nama_tenant,atas_nama,periode_pembayaran,alamat
					FROM	pro_tagihan_telephone
					WHERE	(UPPER(id_tagihan_tlp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(no_tagihan_tlp) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'id_tagihan_tlp' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode( $this->paging($ls_sql) );
	}

	function GetJSONdetail($id){
		$ls_sql	= "	SELECT	id_tagihan_tlp,id_tagihan_tlp_dtl,
							biaya_tagihan,biaya_adm_bank,
							keterangan_tagihan
					FROM	pro_tagihan_telephone_dtl
					WHERE	id_tagihan_tlp = '$id' AND (UPPER(id_tagihan_tlp) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(keterangan_tagihan) LIKE '%".strtoupper(post('keyword'))."%')
					ORDER BY ".(post('sort')=='' ? 'id_tagihan_tlp_dtl' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));	
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('pro_tagihan_telephone', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('pro_tagihan_telephone', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_id_tagihan_tlp){
		$result = $this->db->query("SELECT	no_tagihan_tlp,id_tagihan_tlp,
											TO_CHAR(tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
											nama_tenant,atas_nama,periode_pembayaran,alamat
									FROM	pro_tagihan_telephone
									WHERE   id_tagihan_tlp = '$as_id_tagihan_tlp'");
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	function GetSingleView($as_id_tagihan_tlp)
	{
		$result = $this->db->query("SELECT	no_tagihan_tlp,id_tagihan_tlp,
											TO_CHAR(tanggal_bayar,'DD/MM/YYYY') tanggal_bayar,
											nama_tenant,atas_nama,periode_pembayaran,alamat
									FROM	pro_tagihan_telephone
									WHERE   id_tagihan_tlp = '$as_id_tagihan_tlp'");
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}

	function DeleteSingle($arr_rule)
	{
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM pro_tagihan_telephone WHERE id_tagihan_tlp= '".$arr_rule['id_tagihan_tlp']."'"))<=0)
			{
				return $this->error_delete.' [id: '.$arr_rule['id_tagihan_tlp']."]<br />";
			}else{
				$this->db->delete('pro_tagihan_telephone', array('id_tagihan_tlp' => $arr_rule['id_tagihan_tlp']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

	function GetCetak($as_no_tagihan_tlp)
	{
		$result1 = $this->db->query(" 	SELECT	*
										FROM	pro_tagihan_telephone
										WHERE	no_tagihan_tlp = '$as_no_tagihan_tlp' ");
		return $result1->row_array();
		
	}
}
?>